package com.isoft.systemprovidor.service.perinfor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.isoft.systemprovidor.bean.ResponseData;
import com.isoft.systemprovidor.bean.ResultCode;
import com.isoft.systemprovidor.dao.perinfor.Perinfor_Relative_Familynember_Dao;
import com.isoft.systemprovidor.entity.perinfor.Perinfor_Relative_Familynember;
import com.isoft.systemprovidor.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class Perinfor_Relative_Familynember_Service {
    @Autowired
    Perinfor_Relative_Familynember_Dao familynember_dao;

    /*查看家庭主要成员信息*/
    public ResponseData selectFamilyNember(String sysuserid){
        ResponseData responseData =new ResponseData();
        if (sysuserid.isEmpty()|| null == sysuserid){
            responseData.setErrorCode(ResultCode.PARAM_IS_BLANK.getCode());
            responseData.setMsg(ResultCode.PARAM_IS_BLANK.getMessage());
            return responseData;
        }
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("sysuserid",sysuserid);
        wrapper.eq("islock",0);
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(familynember_dao.selectList(wrapper));
        return responseData;
    }

    /*修改家庭主要成员信息*/
    public boolean changeFamilyNember(Perinfor_Relative_Familynember familynember){
        if((null == familynember)||(!IdUtil.idCheck(familynember.getId()))||(familynember.getSysuserid().isEmpty())){
            return false;
        }
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("sysuserid",familynember.getSysuserid());
        wrapper.eq("id",familynember.getId());
        return familynember_dao.update(familynember,wrapper)>0;
    }

    /*添加家庭主要成员信息*/
    public boolean insertFamilyNember(Perinfor_Relative_Familynember familynember){
        if((null == familynember)||(familynember.getSysuserid().isEmpty())){
            return false;
        }
        return familynember_dao.insert(familynember)>0;
    }
    /*删除家庭主要成员信息(逻辑删除)*/
    public boolean islockFamilyNember(Integer id ,String sysuserid){
        if (id==null|| sysuserid.isEmpty()){
            return false;
        }
        Perinfor_Relative_Familynember familynember = new Perinfor_Relative_Familynember();
        familynember.setIslock(1);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        wrapper.eq("sysuserid",sysuserid);
        return familynember_dao.update(familynember,wrapper)>0;
    }
}
